﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using MotoreDataBase;

namespace MvcSite.Models
{
    [Nome("Album")]
    [NonQuery("SelectFromName", "SELECT nome FROM Album WHERE nome = @nome_album")]
    public class Album
    {
        [Nome("Id")]
        [TableDefinition(TipoDatiDb.INT, 0, false, true, true)]
        public int Id { get; set; }
        [Nome("Nome")]
        public string Nome { get; set; }
        [Nome("N_Foto")]
        public int N_Foto { get; set; }
        
        public Foto LastFoto { get; set; }
        private List<Foto> _listFoto;
        public List<Foto> ListFoto 
        {
            get
            {
                if (_listFoto == null)
                    _listFoto = new List<Foto>();   
                return _listFoto;
            }
            set
            {
                _listFoto = value;
            }
        }
        public Album()
        { }

        public Album(SqlDataReader reader)
        {
            this.Id = int.Parse(reader["id"].ToString());
            this.Nome = reader["nome"].ToString();
        }

        public Album(string Nome, int N_Foto)
        {
            this.Nome = Nome;
            this.N_Foto = N_Foto;
            this.LastFoto = new Foto();
        }

        public Album(int id,string Nome, int N_Foto)
        {
            this.Id = id;
            this.Nome = Nome;
            this.N_Foto = N_Foto;
            this.LastFoto = new Foto();
        }

        // override object.Equals
        public override bool Equals(object obj)
        {

            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }
            
            if(this.Nome.Equals(((Album)obj).Nome))
                return true;
            else
            {
                return false;
            }
        }

        // override object.GetHashCode
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

    }
}